package com.cn.wanxi.servlet;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.ProductModel;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * servlet这一个层和页面进行对接
 */
@WebServlet("/company")
public class CompanyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        CompanyModel companyModel = new CompanyModel();
        //这里是以key-value的形式进行返回，req.setAttribute括号里面两个参数，第一个参数就是key，第二个参数就是value
//        key是我们在页面要调用的值，value是页面得到的值，key的名字随便定义，更具自己的意思
        req.setAttribute("companyModel", companyModel);//将值存入jsp的内置对象

        NavModel navModel = new NavModel();
        List<NavModel> navModelList = navModel.getList();//这里讲返回的list集合进行接收，然后返回到页面
        req.setAttribute("navModelList", navModelList);


//        -----------------------------公司信息轮播-----------------------
        ProductModel productModel = new ProductModel();
        List<ProductModel> companyLunBoList = productModel.getCompanyLunBoList();//这里讲返回的list集合进行接收，然后返回到页面
        req.setAttribute("companyLunBoList", companyLunBoList);

        req.getRequestDispatcher("/jsp/company.jsp").forward(req, resp);//返回公司页面
    }
}
